package com.crm.service.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.model.BizProjectLevel;
import com.crm.model.ServiceInfo;
import com.crm.service.BizProjectLevelService;
import com.crm.service.ServiceInfoService;
import com.crm.util.JsonUtil;
import com.crm.util.ResponseUtil;
import com.github.pagehelper.Page;

@Controller
@RequestMapping("/serviceInfo")
public class ServiceInfoController {
	
	@Autowired
	private ServiceInfoService serviceInfoService;

	@Autowired
	private BizProjectLevelService levelService;
	
	@RequestMapping("/index")
	public String index(){
		return "serviceCenter/infoBulletin";
	}
	
	@RequestMapping("/getAll")
	@ResponseBody
	public void getAll(HttpServletRequest request,HttpServletResponse response,Page<ServiceInfo> page,ServiceInfo info){
		
		Page<ServiceInfo> list = (Page<ServiceInfo>) serviceInfoService.selectAll(page,info);
		
		ResponseUtil.resultPage(response,request,list);
	}
	
	@RequestMapping("/addNewRecord")
	@ResponseBody
	public Map<String, Object> addNewRecord(ServiceInfo info){
		
		Map<String, Object> map = new HashMap<>();
		
		serviceInfoService.insert(info);
		
		map.put("status", "success");
		map.put("msg", "新增成功！");
		
		return map;
	}
	
	@RequestMapping("/updateRecord")
	@ResponseBody
	public Map<String, Object> updateRecord(ServiceInfo info){
		
		Map<String, Object> map = new HashMap<>();
		
		serviceInfoService.updateByPrimaryKey(info);
		
		map.put("status", "success");
		map.put("msg", "修改成功！");
		
		return map;
	}
	
	@RequestMapping("/showLevel")
	@ResponseBody
	public void showLevel(HttpServletRequest request,HttpServletResponse response,BizProjectLevel t){
		Page<BizProjectLevel> page = new Page<BizProjectLevel>();
		List<BizProjectLevel> list = levelService.selectAll(page, t);
		ResponseUtil.result(response, JsonUtil.toJsonStr(list));
	}
	
	@RequestMapping("/prohibit")
	@ResponseBody
	public Map<String, Object> prohibit(String infoId){
		
		Map<String, Object> map = new HashMap<>();
		
		serviceInfoService.prohibit(infoId);
		
		map.put("status", "success");
		map.put("msg", "禁用成功！");
		
		return map;
	}
	
	@RequestMapping("/awaken")
	@ResponseBody
	public Map<String, Object> awaken(String infoId){
		
		Map<String, Object> map = new HashMap<>();
		
		serviceInfoService.awaken(infoId);
		
		map.put("status", "success");
		map.put("msg", "启用成功！");
		
		return map;
	}
}
